//
//  FootPlayView.m
//  ProJectB_1
//
//  Created by lanou3g on 16/8/16.
//  Copyright © 2016年 yangshukai. All rights reserved.
//

#import "FootPlayView.h"

@implementation FootPlayView

- (void)setPlayViewModel:(PlayViewModel *)playViewModel{
    
    [_slider addTarget:self action:@selector(changeValueAction:) forControlEvents:(UIControlEventValueChanged)];
    _playViewModel = playViewModel;
    
}

- (void)changeValueAction:(id *)sender{
    PlayerManager *manager = [PlayerManager defaultManager];
    [manager seekToNewTime:_slider.value];
}

- (IBAction)lastMusic:(id)sender {
    [[PlayerManager defaultManager] lastMusic];
    //利用block将当前播放的单元传出 方便刷新播放的信息（图片 title等）
    if (_selectRadioBlock != nil) {
        _selectRadioBlock([PlayerManager defaultManager].playIndex);
    }
    // 将播放按钮变成暂停标识
    UIButton *button = [self viewWithTag:20002];
    [button setTitle:@"暂停" forState:(UIControlStateNormal)];
}

- (IBAction)playAndPause:(id)sender {
    PlayerManager *manager = [PlayerManager defaultManager];
    UIButton *button = [self viewWithTag:20002];
    // 判断播放状态
    if (manager.playState == PlayerStatePlay) {
        [manager pause];
        // 改变标识
        [button setTitle:@"暂停" forState:(UIControlStateNormal)];
    }else{
        [manager play];
        // 改变标识
        [button setTitle:@"播放" forState:(UIControlStateNormal)];
    }

}

- (IBAction)nextMusic:(id)sender {
    [[PlayerManager defaultManager]nextMusic];
    //利用block将当前播放的单元传出 方便刷新播放的信息（图片 title等）
    if (_selectRadioBlock != nil) {
        _selectRadioBlock([PlayerManager defaultManager].playIndex);
    }
    // 将播放按钮变成暂停标识
    UIButton *button = [self viewWithTag:20002];
    [button setTitle:@"暂停" forState:(UIControlStateNormal)];

}
- (IBAction)changeType:(id)sender {
    
    if ([PlayerManager defaultManager].playType == PlayTypeSingle) {
        [PlayerManager defaultManager].playType = PlayTypeRandom;
        // 将播放按钮变成暂停标识
        UIButton *button = [self viewWithTag:20004];
        [button setTitle:@"随" forState:(UIControlStateNormal)];
    }else if ([PlayerManager defaultManager].playType == PlayTypeRandom){
        [PlayerManager defaultManager].playType = PlayTypeList;
        // 将播放按钮变成暂停标识
        UIButton *button = [self viewWithTag:20004];
        [button setTitle:@"顺" forState:(UIControlStateNormal)];
    }else if ([PlayerManager defaultManager].playType == PlayTypeList){
        [PlayerManager defaultManager].playType = PlayTypeSingle;
        // 将播放按钮变成暂停标识
        UIButton *button = [self viewWithTag:20004];
        [button setTitle:@"1" forState:(UIControlStateNormal)];
    }
}

@end
